package org.ccay.audit.service.impl;

import java.io.Serializable;
import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;

import org.ccay.async.AsyncMessage;
import org.ccay.async.IMessageProcessor;
import org.ccay.audit.service.ILogService;
import org.ccay.audit.vo.LogVO;
import org.ccay.core.exception.ApplicationException;
import org.springframework.beans.factory.InitializingBean;

/**
 * 审计日志消息处理器。
 * 	
 * @author chaowangbang
 * @since Dec 13, 2011
 */
@Named
public class AuditLogProcessor implements IMessageProcessor, InitializingBean {
	
	/** 审计日志服务 **/
	@Inject
	private ILogService logService;
	
	/**
	 * 设置日志记录服务。
	 * 	
	 * @author chaowangbang
	 * @since Dec 14, 2011
	 * @param logService
	 */
	public void setLogService(ILogService logService) {
		this.logService = logService;
	}

	/* (non-Javadoc)
	 * @see www.ccay.org.ccay.core.async.MessageProcessor#process(www.ccay.org.ccay.core.async.Message)
	 */
	public void process(AsyncMessage message) throws ApplicationException {
		Serializable content = message.getContent();
		if(content instanceof LogVO) {
			logService.createLog((LogVO)content);
		} else if(content instanceof List) {
			logService.createLogList((List<LogVO>)content);
		}
	}

	/* (non-Javadoc)
	 * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
	 */
	public void afterPropertiesSet() throws ApplicationException {
		assert(logService!=null);
	}

}
